package com.hbnulk.test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyFrame2 extends JFrame implements MouseListener {
    public MyFrame2(){
        //设置界面的宽高
        this.setSize(603,680);
        //设置标题
        this.setTitle("测试鼠标监听事件");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面加载后居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //取消默认的居中放置，取消才会按照XY形式放置组件
        this.setLayout(null);

        //给整个窗体添加鼠标监听
        this.addMouseListener(this);

        //让界面显示出来
        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("鼠标单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("鼠标按下");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("鼠标释放");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("鼠标移入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("鼠标移出");

    }
}
